//
//  MMHttpTools.m
//  BAISIBUDEJIE
//
//  Created by li  bo on 16/5/20.
//  Copyright © 2016年 li  bo. All rights reserved.
//

#import "MMHttpTools.h"

@implementation MMHttpTools

+(void)getWithURL:(NSString *)url parameters:(NSDictionary *)parames success:(void (^)(id))lbsuccess failure:(void (^)(NSError *))lbfailure
{
    AFHTTPSessionManager  *manager=[AFHTTPSessionManager manager];

    [manager GET:url parameters:parames progress:^(NSProgress * _Nonnull downloadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        lbsuccess(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        lbfailure(error);
    }];

}
+(void)postWithURL:(NSString *)url parameters:(NSDictionary *)parames success:(void (^)(id))lbsuccess failure:(void (^)(NSError *))lbfailure
{

    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager POST:url parameters:parames progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        lbsuccess(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        lbfailure(error);

    }];

}
+(void)postWithURL:(NSString *)url parameters:(NSDictionary *)parames data:(NSData *)data success:(void (^)(id))lbsuccess failure:(void (^)(NSError *))lbfailure{

    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
    [manager POST:url parameters:parames constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        [formData  appendPartWithFileData:data name:@"pic" fileName:@"test.jpg" mimeType:@"image/jpeg"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        lbsuccess(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        lbfailure(error);
    }];
    
}


@end
